import {http} from '@/utils/http'

// 菜单接口类型定义
export interface MenuItem {
  id: number
  title: string
  pid: number
  remark: string
  curator: string
  sort: number
  status: number
  create_time?: number
  update_time?: number
  children?: MenuItem[]
}

export interface MenuForm {
  id?: number
  title: string
  pid: any
  remark: string
  curator: string
  sort: number
  status: number
}

export interface FilterParams {
  status?: number
  title?: string
}

// API 接口
export const menuApi = {
  // 获取菜单列表
  getMenuList(params: FilterParams) {
    return http.get<any>('/api/organization/index',{ params })
  },

  // 获取菜单树
  getMenuTree() {
    return http.get<any>('/api/organization/tree')
  },

  // 获取扁平菜单列表（用于树形选择器）
  getMenuFlatList(system_user_id: string) {
    return http.get<any>('/api/organization/flatList?system_user_id='+system_user_id)
  },

  // 获取菜单详情
  getMenuDetail(id: number) {
    return http.get<any>('/api/organization/read?id='+id)
  },

  // 新增菜单
  createMenu(data: MenuForm) {
    return http.post('/api/organization/save', data);
  },

  // 更新菜单
  updateMenu(id: number, data: MenuForm) {
    data.id = id;
    return http.post('/api/organization/update', data);
  },

  // 删除菜单
  deleteMenu(id: number) {
    return http.post('/api/organization/delete', {id:id});
  },

  // 更新菜单状态
  updateMenuStatus(id: number, status: number) {
    return http.post('/api/organization/update_status', {id:id,status:status});
  },

  // 获取角色列表
  getRoleList(id: number) {
    return http.get<any>('/api/organization/roleList?id='+id)
  },

  // 获取成员列表
  getMemberList(id: number) {
    return http.get<any>('/api/organization/memberList?id='+id)
  },

  // 获取全部角色列表
  roleAllList() {
    return http.get<any>('/api/organization/roleAllList')
  },

}